//耗时50分钟，满分
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
bool** CreatMat(const int&n)
{
    bool** mat = new bool* [n];
    for (int i = 0; i < n; i++)
    {
        mat[i] = new bool[n];
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            mat[i][j] = false;
        }
    }
    return mat;
}
bool* CreatFalseN(const int&n)
{
    bool* status = new bool[n];
    for (int i = 0; i < n; i++)
    {
        status[i] = false;
    }
    return status;
}
void MatFloodStart(bool**&startMap, int n, int now, bool*& visit, bool*&status)
{
    if (!visit[now])
    {
        visit[now] = true;
        status[now] = true;
        for (int i = 0; i < n; i++)
        {
            if (startMap[now][i])
            {
                MatFloodStart(startMap, n, i, visit,status);
            }
        }
    }
        return;
    
}
void MatFloodStop(bool**&startMap, int n, int now, bool*& visit, bool*& status)
{
    if (!visit[now])
    {
        visit[now] = true;
        status[now] = false;
        for (int i = 0; i < n; i++)
        {
            if (startMap[now][i])
            {
                MatFloodStop(startMap, n, i, visit, status);
            }
        }
    }
    return;

}
int MatCount(bool*& status,const int&n)
{
    int count = 0;
    for (int i = 0; i < n; i++)
    {
        if (status[i]) { count++; }
    }
    return count;
}
int main()
{
    int n,q;
    cin >> n >> q;
    //建立n*n的启动、停止有向图矩阵
    bool** startMap = CreatMat(n);
    bool** stopMap = CreatMat(n);
    
    //第i个的依赖输入
    for (int i = 0; i < n; i++)
    {
        int tmp;
        cin >> tmp;
        while (tmp-- > 0)
        {
            int tmp1;
            cin >> tmp1;
            tmp1--;
            startMap[i][tmp1] = true;
            stopMap[tmp1][i] = true;
        }
    }
    //初始一个状态表示数组
    bool* status = CreatFalseN(n);
    //cin >> q;
    for (int i = 0; i < q; i++)
    {
        int tmp;
        cin >> tmp;
        bool* visit = CreatFalseN(n);
        int start;
        cin >> start;
        start--;
        //启动
        if (tmp)
        {
            MatFloodStart(startMap, n,start, visit, status);
        }
        else
        {
            MatFloodStop(stopMap, n, start, visit, status);
        }
        cout<<MatCount(status,n)<<endl;
        //break;
    }
}